/**
 * Created by DELL on 2017/7/6.
 */
(function () {
    var bannerId=common.getQueryString('id');
    var $form=$("form");
    var $photo=$("#photo");
    $form.validate({
        /**
         * ignore：忽略某些元素不验证
         * @type {String}
         * 例如：ignore: ".ignore" ，忽略所有的带ignore class 的标签
         */
        ignore: ".ignore",
        rules: {
            bannerType: {
                required: true
            },
            sort: {
                digits: true,
                max:98
            },
            linkAddress:{
                maxlength:120
            }
        }
    });
    window.formObject=$form;
    var userInfo=common.getLocalData(common.agentSysCacheWord).user;

    $.post(window.globalHost + common.bannerDetailPath, {id:bannerId}).success(function(data) {
        var detailInfo = common.transformData(data);
        //初始化所有input的值
        common.initInputByName({
            id:bannerId,
            picturePath:detailInfo.picturePath,
            bannerName:detailInfo.bannerName,
            linkAddress:detailInfo.linkAddress,
            sort:detailInfo.sort==99?"":detailInfo.sort
        });
        common.getRadioChecked("bannerType",detailInfo.bannerType);
        common.getRadioChecked("status",detailInfo.status);

        var bannerPhotoGallery=$("#banner-photo").gallery({
            readOnly:false,
            title:"上传banner图片",
            url:window.globalHost +common.uploadImagePort,
            paramName:"uploadData",
            fileFolder:{folder:"banner",id:userInfo.id,fileName:"sys_banner_"+new Date().getTime()},
            returnPathName:"filePath",
            maxFiles:1,
            filePaths:detailInfo.picturePath?[detailInfo.picturePath]:[],
            uploadCallback:function () {
                var path=bannerPhotoGallery.getFilePaths();
                $photo.val(!!path.length?path.join(","):"")
            },
            deleteCallback:function () {
                var path=bannerPhotoGallery.getFilePaths();
                $photo.val(!!path.length?path.join(","):"");
            }
        });
    });

}).call(this);